package cn.rxmind.dlicense.core.factory;

import cn.rxmind.dlicense.core.base.DLicenseContent;
import cn.rxmind.dlicense.core.constants.DLicenseConstants;
import de.schlichtherle.license.LicenseContent;

import java.util.Date;

/**
 *
 * 分离构造LicenseContent的逻辑
 *
 * @author renxin
 * @email renxinzhiliangzhi@163.com
 * @date 2021/4/13 9:27 上午
 */
public class DLicenseContentFactory {

    private DLicenseContentFactory(){}

    public static LicenseContent createLicenseContent(DLicenseContent dLicenseContent){

        LicenseContent licenseContent = new LicenseContent();
        Date notBefore = dLicenseContent.getLicenseActiveTimeRule().getNotBefore();
        Date notAfter = dLicenseContent.getLicenseActiveTimeRule().getNotAfter();
        licenseContent.setSubject(DLicenseConstants.SUBJECT);
        licenseContent.setConsumerAmount(DLicenseConstants.CONSUMER_AMOUNT);
        licenseContent.setConsumerType(DLicenseConstants.CONSUMER_TYPE);
        licenseContent.setHolder(DLicenseConstants.DEFAULT_HOLDER_AND_ISSUER);
        licenseContent.setInfo(DLicenseConstants.INFO);
        licenseContent.setIssued(new Date());
        licenseContent.setIssuer(DLicenseConstants.DEFAULT_HOLDER_AND_ISSUER);
        licenseContent.setNotBefore(notBefore);
        licenseContent.setNotAfter(notAfter);

        licenseContent.setExtra(dLicenseContent);
        return licenseContent;
    }

}
